﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;
using System.Data;

public partial class Administrator_Controls_HomeLink : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
            loadData();
    }
    private void loadData()
    {
        try
        {
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath("~/slide.xml"));
            base.bindRepeater(rptData, objDS.Tables[0], divMessage);
        }
        catch (Exception ex) { divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message); }
    }
    protected void ddlAction_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            //if (ddlAction.SelectedValue.Equals("0"))
            //    return;
            string selectedItems = GetSelectedItems(rptData, "chkBox");
            if (String.IsNullOrEmpty(selectedItems))
            {
                Javascripts.Alert(Page, "Phải chọn ít nhất 1 link!");
                return;
            }
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath("~/slide.xml"));
            ObjDT = objDS.Tables[0];
            string[] selected = selectedItems.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            int index;
            for (int i = selected.Length; i > 0; i--)
            {
                index = Convert.ToInt32(selected[i - 1]) - 1;
                ObjDT.Rows.RemoveAt(index);
            }
            objDS.WriteXml(Server.MapPath("~/slide.xml"));
            loadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi hệ thống", "Phát hiện lỗi sau: " + ex.Message);
        }
    }
}
